package com.liliudong.pinkyponk.biz.sys.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liliudong.pinkyponk.biz.sys.entity.SysUserRole;
import com.liliudong.pinkyponk.biz.sys.mapper.SysUserRoleMapper;
import com.liliudong.pinkyponk.biz.sys.service.SysUserRoleService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * SysUserRoleService
 *
 * @author liliudong
 * @date 2022-06-03 22:46
 **/
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements
        SysUserRoleService {

    @Override
    public void removeByUserId(Long userId) {
        baseMapper.delete(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getUserId, userId));
    }

    @Override
    public void saveBatchByUserId(Long userId, List<Integer> roleIds) {
        List<SysUserRole> list = roleIds.stream().map(roleId ->
                SysUserRole.builder().roleId(roleId).userId(userId).build()
        ).collect(Collectors.toList());
        this.saveBatch(list);
    }
}
